package cn.hotel.controller.user;

import cn.hotel.entity.Room;
import cn.hotel.entity.RoomType;
import cn.hotel.response.ResponseTool;
import cn.hotel.response.Result;
import cn.hotel.service.RoomService;
import cn.hotel.service.RoomTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@RestController
@RequestMapping(value = "/hotel/room")
public class UserRoomController {
    @Resource
    private RoomTypeService roomTypeService;

    @Resource
    private RoomService roomService;

    /**
     * 获取当前酒店的全部房间类型
     * @return
     */
    @PostMapping(value = "")
    public Result getAllRoomType(){
        List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
        return ResponseTool.success(roomTypeList);
    }

    /**
     * 根据房间类别的id去查找对应的房间信息
     * @param typeId
     * @return  返回查询到的所有房间中的第一个
     */
    @GetMapping("/{typeId}")
    public Result getRoomByTypeId(@PathVariable("typeId") String typeId){
        log.info("typeId{}",typeId);
        Room room = roomService.queryRoomByTypeId(typeId);
        log.info("room{}",room);
        return ResponseTool.success(room);
    }
}
